﻿<%@ Page Title="Quản lý chuyên gia" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="Dost.Khcn.Web.ChuyenGia.Edit" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <link href="/Content/fileuploader.css" rel="stylesheet" />
    <script src="/Scripts/fileuploader.js"></script>

    <h2><%=Resources.GlobalStrings.Edit %> chuyên gia</h2>
    <p></p>
    <span class="failureNotification">
        <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></span>
    <%--<div class="message success">Success Message</div>--%>
    <div>
        <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
            <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Thông tin chung</a></li>
                <li class="ui-state-default ui-corner-top"><a href="#tabs-2">Quá trình công tác</a></li>
                <li class="ui-state-default ui-corner-top"><a href="#tabs-3">Công trình nghiên cứu</a></li>
                <li class="ui-state-default ui-corner-top"><a href="#tabs-4">Đề tài cấp Nhà Nước/cấp Bộ</a></li>
                <li class="ui-state-default ui-corner-top"><a href="#tabs-5">Đề tài cấp Tỉnh</a></li>
                <li class="ui-state-default ui-corner-top"><a href="#tabs-6">Giải thưởng về KH&CN</a></li>
                <li class="ui-state-default ui-corner-top"><a href="#tabs-7">Files</a></li>
            </ul>
            <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <table>
                    <tr>
                        <td colspan="5"><h3>Thông tin chung</h3></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Họ tên:</td>
                        <td><input id="HoTen" data-bind="value: ChuyenGia().HoTen" class="validate[required] name" /></td>
                        <td style="width: 10px;"></td>
                        <td style="text-align: right;">Giới tính:</td>
                        <td><input type="radio" name="GioiTinh" data-bind="checked: ChuyenGia().GioiTinh, checkedValue: true" /> Nam
                            <input type="radio" name="GioiTinh" data-bind="checked: ChuyenGia().GioiTinh, checkedValue: false" /> Nữ</td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Năm sinh:</td>
                        <td><input id="NamSinh" data-bind="value: ChuyenGia().NamSinh" class="validate[custom[onlyNumberSp]] date" /></td>
                        <td></td>
                        <td style="text-align: right;">Dân tộc:</td>
                        <td><input data-bind="value: ChuyenGia().DanToc" class="date" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Địa chỉ liên hệ:</td>
                        <td colspan="4"><input data-bind="value: ChuyenGia().DiaChi" class="longname" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Điện thoại:</td>
                        <td><input data-bind="value: ChuyenGia().DienThoai" class="name" /></td>
                        <td></td>
                        <td style="text-align: right;">Email:</td>
                        <td><input id="Email" data-bind="value: ChuyenGia().Email" class="name" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Học hàm:</td>
                        <td><select data-bind="options: $root.HocHams, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().HocHamId"></select></td>
                        <td></td>
                        <td style="text-align: right;">Năm được phong học hàm:</td>
                        <td><input id="NamHocHam" data-bind="value: ChuyenGia().NamHocHam" class="validate[custom[onlyNumberSp]] date" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Học vị:</td>
                        <td colspan="4"><select data-bind="options: $root.HocVis, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().HocViId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Chức vụ:</td>
                        <td><input data-bind="value: ChuyenGia().ChucVu" class="name" /></td>
                        <td></td>
                        <td style="text-align: right;">Chức danh nghiên cứu:</td>
                        <td><input data-bind="value: ChuyenGia().ChucDanh" class="name" /></td>
                    </tr>
                    <tr>
                        <td colspan="5" style="padding-top: 15px;">Đơn vị đang công tác (hoặc trước khi nghỉ hưu):</td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Tên đơn vị:</td>
                        <td><input data-bind="value: ChuyenGia().TenDonVi" class="name" /></td>
                        <td style="width: 10px;"></td>
                        <td style="text-align: right;">Điện thoại:</td>
                        <td><input data-bind="value: ChuyenGia().DienThoaiDonVi" class="name" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Địa chỉ:</td>
                        <td colspan="4"><input data-bind="value: ChuyenGia().DiaChiDonVi" class="longname" /></td>
                    </tr>
                    <tr>
                        <td colspan="5" style="padding-top: 15px;"></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Lĩnh vực nghiên cứu:</td>
                        <td colspan="4">
                            <select data-bind="options: $root.NhomLinhVucs, optionsText: 'MaTen', optionsValue: 'Id', value: selectedNhomLinhVuc"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Ngành nghiên cứu:</td>
                        <td colspan="4"><select data-bind="options: $root.LinhVucs, optionsText: 'MaTen', optionsValue: 'Id', value: ChuyenGia().LinhVucId"></select></td>
                    </tr>
                    <tr>
                        <td colspan="5"><h3>Quá trình đào tạo</h3></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Chuyên ngành đào tạo:</td>
                        <td colspan="4"><select data-bind="options: $root.ChuyenNganhs, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().ChuyenNganhId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Hình thức đào tạo:</td>
                        <td colspan="4"><select data-bind="options: $root.HinhThucDaoTaos, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().HinhThucDaoTaoId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Cơ sở đào tạo:</td>
                        <td colspan="4"><select data-bind="options: $root.CoSoDaoTaos, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().CoSoDaoTaoId"></select></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Nước cấp:</td>
                        <td><select data-bind="options: $root.QuocGias, optionsText: 'Ten', optionsValue: 'Id', value: ChuyenGia().QuocGiaId"></select></td>
                        <td></td>
                        <td style="text-align: right;">Năm nhận học vị:</td>
                        <td><input id="NamHocVi" data-bind="value: ChuyenGia().NamHocVi" class="validate[custom[onlyNumberSp]] date" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Tên luận án:</td>
                        <td colspan="4"><textarea data-bind="value: ChuyenGia().TenLuanAn" class="longname"></textarea></td>
                    </tr>
                    <tr>
                        <td colspan="5" style="padding-top: 15px;"></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Trình độ ngoại ngữ:</td>
                        <td colspan="4"><input data-bind="value: ChuyenGia().NgoaiNgu" class="name" /></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;">Thành tựu hoạt động<br/> KH&CN khác:</td>
                        <td colspan="4"><textarea data-bind="value: ChuyenGia().ThanhTuuKhcnKhac" class="longname"></textarea></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;"></td>
                        <td><p><button class="submitButton" data-bind="click: save"><%=Resources.GlobalStrings.Save %></button></p></td>
                        <td></td>
                        <td style="text-align: right;"></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td style="text-align: right;"></td>
                        <td></td>
                        <td></td>
                        <td style="text-align: right;"></td>
                        <td></td>
                    </tr>
                </table>
                
            </div>
            <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <div id="QuaTrinhCongTacContainer"></div>
            </div>
            <div id="tabs-3" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <div id="CongTrinhContainer"></div>
            </div>
            <div id="tabs-4" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <div id="DeTaiNhaNuocContainer"></div>
            </div>
            <div id="tabs-5" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <div id="DeTaiCapTinhContainer"></div>
            </div>
            <div id="tabs-6" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <div id="GiaiThuongKhcnContainer"></div>
            </div>
            <div id="tabs-7" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
                <div id="ChuyenGiaFileContainer"></div>
                <div id="file-uploader">
                    <noscript>
                        <p>Please enable JavaScript to use file uploader.</p>
                    </noscript>         
                </div>
            </div>
        </div>
    </div>
    
    <div>
        <asp:DropDownList ID="ddlExportType" runat="server">
            <asp:ListItem Value="1">Word</asp:ListItem>
            <asp:ListItem Value="2">Excel</asp:ListItem>
            <asp:ListItem Value="3">Pdf</asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
    </div>

    <input id="btnCancel" type="button" value="<%=Resources.GlobalStrings.Cancel %>" class="submitButton" onclick="javascript: window.location = 'List.aspx';" />
    
    <script type="text/javascript">
        var chuyenGiaId = <%=Request.Params["id"] %>;
        var chuyenGiaViewModel;
        $(document).ready(function () {
            //$('.message').AutoHideMessage({'autoHide': true, 'time':10000 });
            $("#tabs").tabs();
            $("#Form1").validationEngine();
        
            // load ChuyenGia data
            $.blockUI();
            $.ajax({
                url: "Edit.aspx/GetChuyenGia",
                data: JSON.stringify({id: chuyenGiaId}),
                type: "post",
                contentType: "application/json",
                async: true,
                success: function (data) {
                    var chuyenGia = ko.mapping.fromJS(data.d);
                    chuyenGiaViewModel = new ChuyenGiaViewModel(chuyenGia);
                    ko.applyBindings(chuyenGiaViewModel);
                }
            });
            
            // load qua trinh cong tac
            LoadQuaTrinhCongTac(chuyenGiaId);
            
            // load cong trinh nghien cuu
            LoadCongTrinhNghienCuu(chuyenGiaId);
            
            // load de tai cap nha nuoc
            LoadDeTaiCapNhaNuoc(chuyenGiaId);
            
            // load de tai cap tinh
            LoadDeTaiCapTinh(chuyenGiaId);
            
            // load giai thuong khcn
            LoadGiaiThuongKhcn(chuyenGiaId);
            
            // files
            LoadChuyenGiaFile(chuyenGiaId);
            
            // fileupload
            var uploader = new qq.FileUploader({
                // The div to hold the uploader in.
                element: document.getElementById('file-uploader'),
                // Enabled to see the traffic in something like Firefox Web Console
                debug: true,
                // Max file size limit
                //sizeLimit: 1048576,
                params: { chuyenGiaId: chuyenGiaId },
                // This fuction is executed once uploaded.
                // This is appends the filenames to a div, but it could be anything!
                //onSubmit: function() {
                    
                //},
                onComplete: function (id, fileName, responseJSON) {
                    if (!responseJSON.success) {
                        alert(responseJSON.message);
                    }
                    // reload files
                    $('#ChuyenGiaFileContainer').jtable('load', { chuyenGiaId: chuyenGiaId });
                },
                // The text that is shown on the upload 'button'
                uploadButtonText: "Tải file ...",
                // The name of the controller and function that will handle the upload.
                action: 'FileUpload.ashx',
                // The file types allowed to be selected.
                //acceptFiles: ['image/jpeg', 'image/jpg', 'image/JPG', 'image/bmp', 'image/gif', 'image/png', 'image/bmp'],
                // Allowed extensions
                //allowedExtensions: ['jpeg', 'jpg', 'png', 'gif', 'bmp'],
                // Allow the user to select more than one file to up load at a time
                multiple: false,
                inputName: 'uploadFile'
            });
        });
    </script>
    
    <script type="text/javascript">
        function ChuyenGiaViewModel(chuyenGia) {
            var self = this;
            // data
            self.ChuyenGia = ko.observable(chuyenGia);
            self.HocHams = ko.observableArray();
            self.HocVis = ko.observableArray();
            self.LinhVucs = ko.observableArray();
            self.ChuyenNganhs = ko.observableArray();
            self.HinhThucDaoTaos = ko.observableArray();
            self.CoSoDaoTaos = ko.observableArray();
            self.QuocGias = ko.observableArray();
            self.NhomLinhVucs = ko.observableArray();
            self.selectedNhomLinhVuc = ko.observable();
            self.AllLinhVucs = {};

            // hoc ham
            $.ajax({
                url: "/DanhMuc/HocHam/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.HocHams(data.d);
                }
            });
            // hoc vi
            $.ajax({
                url: "/DanhMuc/HocVi/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.HocVis(data.d);
                }
            });
            // nhomlinh vuc
            $.ajax({
                url: "/DanhMuc/LinhVuc/NhomLinhVuc.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.NhomLinhVucs(data.d);
                }
            });
            // linh vuc
            $.ajax({
                url: "/DanhMuc/LinhVuc/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.AllLinhVucs = data.d;
                    self.LinhVucs(data.d);
                }
            });
            // chuyen nganh
            $.ajax({
                url: "/DanhMuc/ChuyenNganh/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.ChuyenNganhs(data.d);
                }
            });
            // hinh thuc dao tao
            $.ajax({
                url: "/DanhMuc/HinhThucDaoTao/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.HinhThucDaoTaos(data.d);
                }
            });
            // co so dao tao
            $.ajax({
                url: "/DanhMuc/CoSoDaoTao/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.CoSoDaoTaos(data.d);
                }
            });
            // quoc gia
            $.ajax({
                url: "/DanhMuc/QuocGia/List.aspx/GetAll",
                type: "post",
                contentType: "application/json",
                async: false,
                success: function (data) {
                    self.QuocGias(data.d);
                }
            });

            // behaviors
            self.selectedNhomLinhVuc.subscribe(function () {
                if (self.selectedNhomLinhVuc() === 0) {
                    self.LinhVucs(self.AllLinhVucs);
                } else {
                    var linhVucs = new Array();
                    $.each(self.AllLinhVucs, function (index, linhVuc) {
                        if (linhVuc.NhomLinhVucId === self.selectedNhomLinhVuc()) {
                            linhVucs.push(linhVuc);
                        }
                    });
                    self.LinhVucs(linhVucs);
                }
            });

            self.save = function () {
                var valid = $("#Form1").validationEngine('validate');
                if (!valid) return false;

                $.blockUI();
                $.ajax({
                    url: "Edit.aspx/Update",
                    data: JSON.stringify({ chuyenGia: ko.mapping.toJS(self.ChuyenGia()) }), // unmapped before send
                    type: "post",
                    contentType: "application/json",
                    dataType: "json",
                    async: true,
                    success: function (result) {
                        if (result.d.Result == "OK") {
                            alert("Cập nhật thành công");
                        } else {
                            alert(result.d.Message);
                        }
                    }
                });
                return false;
            };

            $.each(self.AllLinhVucs, function (index, linhVuc) {
                if (linhVuc.Id === chuyenGia.LinhVucId()) {
                    self.selectedNhomLinhVuc(linhVuc.NhomLinhVucId);
                }
            });
        }

        function LoadQuaTrinhCongTac(chuyenGiaId) {
            $('#QuaTrinhCongTacContainer').jtable({
                title: '&nbsp;',
                sorting: false,
                //defaultSorting: 'Id DESC',
                actions: {
                    listAction: 'QuaTrinhCongTac.aspx/List',
                    deleteAction: 'QuaTrinhCongTac.aspx/Delete',
                    createAction: 'QuaTrinhCongTac.aspx/Create',
                    updateAction: 'QuaTrinhCongTac.aspx/Update'
                },
                fields: {
                    Id: {
                        title: "STT",
                        key: true,
                        create: false,
                        edit: false,
                        width: '1%'
                    },
                    ChuyenGiaId: {
                        type: 'hidden',
                        defaultValue: chuyenGiaId
                    },
                    ThoiGian: {
                        title: 'Thời gian',
                        inputClass: 'validate[required]'
                    },
                    TenToChuc: {
                        title: 'Tên tổ chức',
                        inputClass: 'validate[required] name'
                    },
                    DiaChi: {
                        title: 'Địa chỉ',
                        inputClass: 'longname'
                    }
                },
                //Initialize validation logic when a form is created
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                //Validate form when it is being submitted
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                //Dispose validation logic when form is closed
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            $('#QuaTrinhCongTacContainer').jtable('load', { chuyenGiaId: chuyenGiaId });
        }
        
        function LoadCongTrinhNghienCuu(chuyenGiaId) {
            $('#CongTrinhContainer').jtable({
                title: '&nbsp;',
                sorting: false,
                //defaultSorting: 'Id DESC',
                actions: {
                    listAction: 'CongTrinhNghienCuu.aspx/List',
                    deleteAction: 'CongTrinhNghienCuu.aspx/Delete',
                    createAction: 'CongTrinhNghienCuu.aspx/Create',
                    updateAction: 'CongTrinhNghienCuu.aspx/Update'
                },
                fields: {
                    Id: {
                        title: "STT",
                        key: true,
                        create: false,
                        edit: false,
                        width: '1%'
                    },
                    ChuyenGiaId: {
                        type: 'hidden',
                        defaultValue: chuyenGiaId
                    },
                    TenCongTrinh: {
                        title: 'Tên công trình',
                        type: 'textarea',
                        inputClass: 'validate[required] longname'
                    },
                    NoiCongBo: {
                        title: 'Nơi công bố',
                        type: 'textarea',
                        inputClass: 'longname'
                    },
                    NamCongBo: {
                        title: 'Năm công bố',
                        inputClass: 'validate[custom[onlyNumberSp]] date'
                    },
                    TacGia: {
                        title: 'Tác giả/đồng tác giả',
                        inputClass: 'name'
                    }
                },
                //Initialize validation logic when a form is created
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                //Validate form when it is being submitted
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                //Dispose validation logic when form is closed
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            $('#CongTrinhContainer').jtable('load', { chuyenGiaId: chuyenGiaId });
        }
        
        function LoadDeTaiCapNhaNuoc(chuyenGiaId) {
            $('#DeTaiNhaNuocContainer').jtable({
                title: '&nbsp;',
                sorting: false,
                //defaultSorting: 'Id DESC',
                actions: {
                    listAction: 'DeTaiCapNhaNuoc.aspx/List',
                    deleteAction: 'DeTaiCapNhaNuoc.aspx/Delete',
                    createAction: 'DeTaiCapNhaNuoc.aspx/Create',
                    updateAction: 'DeTaiCapNhaNuoc.aspx/Update'
                },
                fields: {
                    Id: {
                        title: "STT",
                        key: true,
                        create: false,
                        edit: false,
                        width: '1%'
                    },
                    ChuyenGiaId: {
                        type: 'hidden',
                        defaultValue: chuyenGiaId
                    },
                    TenDeTai: {
                        title: 'Tên đề tài',
                        type: 'textarea',
                        inputClass: 'validate[required] longname'
                    },
                    ChuyenNganhId: {
                        title: 'Chuyên Ngành',
                        options: '/DanhMuc/ChuyenNganh/List.aspx/GetOptions'
                    },
                    LinhVucId: {
                        title: 'Lĩnh vực',
                        options: '/DanhMuc/LinhVuc/List.aspx/GetOptions'
                    },
                    NamThucHien: {
                        title: 'Năm thực hiện',
                        inputClass: 'name'
                    },
                    TacGia: {
                        title: 'Tác giả/đồng tác giả',
                        inputClass: 'name'
                    }
                },
                //Initialize validation logic when a form is created
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                //Validate form when it is being submitted
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                //Dispose validation logic when form is closed
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            $('#DeTaiNhaNuocContainer').jtable('load', { chuyenGiaId: chuyenGiaId });
        }
        
        function LoadDeTaiCapTinh(chuyenGiaId) {
            $('#DeTaiCapTinhContainer').jtable({
                title: '&nbsp;',
                sorting: false,
                //defaultSorting: 'Id DESC',
                actions: {
                    listAction: 'DeTaiCapTinh.aspx/List',
                    deleteAction: 'DeTaiCapTinh.aspx/Delete',
                    createAction: 'DeTaiCapTinh.aspx/Create',
                    updateAction: 'DeTaiCapTinh.aspx/Update'
                },
                fields: {
                    Id: {
                        title: "STT",
                        key: true,
                        create: false,
                        edit: false,
                        width: '1%'
                    },
                    ChuyenGiaId: {
                        type: 'hidden',
                        defaultValue: chuyenGiaId
                    },
                    TenDeTai: {
                        title: 'Tên dự án/đề tài',
                        type: 'textarea',
                        inputClass: 'validate[required] longname'
                    },
                    TinhThanhPhoId: {
                        title: 'Tỉnh/thành phố',
                        options: '/DanhMuc/TinhThanhPho/List.aspx/GetOptions'
                    },
                    NamThucHien: {
                        title: 'Năm thực hiện',
                        inputClass: 'name'
                    },
                    TacGia: {
                        title: 'Tác giả/đồng tác giả',
                        inputClass: 'name'
                    }
                },
                //Initialize validation logic when a form is created
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                //Validate form when it is being submitted
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                //Dispose validation logic when form is closed
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            $('#DeTaiCapTinhContainer').jtable('load', { chuyenGiaId: chuyenGiaId });
        }
        
        function LoadGiaiThuongKhcn(chuyenGiaId) {
            $('#GiaiThuongKhcnContainer').jtable({
                title: '&nbsp;',
                sorting: false,
                //defaultSorting: 'Id DESC',
                actions: {
                    listAction: 'GiaiThuongKhcn.aspx/List',
                    deleteAction: 'GiaiThuongKhcn.aspx/Delete',
                    createAction: 'GiaiThuongKhcn.aspx/Create',
                    updateAction: 'GiaiThuongKhcn.aspx/Update'
                },
                fields: {
                    Id: {
                        title: "STT",
                        key: true,
                        create: false,
                        edit: false,
                        width: '1%'
                    },
                    ChuyenGiaId: {
                        type: 'hidden',
                        defaultValue: chuyenGiaId
                    },
                    NoiDung: {
                        title: 'Hình thức và nội dung giải thưởng',
                        type: 'textarea',
                        inputClass: 'validate[required] longname'
                    },
                    NamTangThuong: {
                        title: 'Năm tặng thưởng',
                        inputClass: 'validate[custom[onlyNumberSp]] date'
                    }
                },
                //Initialize validation logic when a form is created
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                //Validate form when it is being submitted
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                //Dispose validation logic when form is closed
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            $('#GiaiThuongKhcnContainer').jtable('load', { chuyenGiaId: chuyenGiaId });
        }
        
        function LoadChuyenGiaFile(chuyenGiaId) {
            $('#ChuyenGiaFileContainer').jtable({
                title: '',
                sorting: false,
                //defaultSorting: 'Id DESC',
                actions: {
                    listAction: 'File.aspx/List',
                    deleteAction: 'File.aspx/Delete'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    FileName: {
                        title: 'Tên file', width: '50%',
                        display: function (data) {
                            return '<a href="/Download.aspx?id=' + data.record.Id + '" target="_blank">' + data.record.FileName + '</a>';
                        }
                    }
                }
            });

            $('#ChuyenGiaFileContainer').jtable('load', { chuyenGiaId: chuyenGiaId });
        }
    </script>
</asp:Content>
